﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Common;
using System.Data;

namespace POS_NEW.Utilites
{
    public static class Extensions
    {
            public static IEnumerable<object[]> ExecuteQuery(
                this DataContext ctx, string query)
            {
                using (DbCommand cmd = ctx.Connection.CreateCommand())
                {
                    
                    cmd.CommandText = query;
                    ctx.Connection.Open();
                    using (DbDataReader rdr =
                        cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (rdr.Read())
                        {
                            object[] res = new object[rdr.FieldCount];
                            rdr.GetValues(res);
                            yield return res;
                        }
                    }
                }
            }
    }
}
